#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

from enum import Enum

import pexpect
from pydantic import BaseModel

from common.env_common import get_install_head_path, adaptation_win_path

ERROR_SQL_EXPECT = ["not logged on", "unknown command", "ERROR at line", "ORA-"]
SQL_TIMEOUT = 180


class RootCommand(str, Enum):
    # 资源接入
    ROOT_COMMAND_SCRIPT_QUERY_ORACLE_INFO = 'oracle_info.sh'
    ROOT_COMMAND_SCRIPT_TEST_ORACLE = 'oracle_test.sh'
    ROOT_COMMAND_SCRIPT_QUERY_ORACLE_ASM = 'oracle_asm_info.sh'
    ROOT_COMMAND_SCRIPT_QUERY_RAC_INFO = 'oracle_rac_info.sh'
    # 备份
    ROOT_COMMAND_ORACLE_NATIVE_BACKUP = 'oracle_native_backup.sh'
    ROOT_ORACLE_NATIVE_ARCHIVE_BACKUP = 'oracle_native_archive_backup.sh'

    ROOT_COMMAND_SCRIPT_CHECK_DB_STATUS = 'oracle_native_check_db_status.sh'
    QUERY_STATUS = 'oraclebackupstatus.sh'
    # 阈值检查
    ROOT_COMMAND_SCRIPT_CHECKARCHIVETHRESHOLD = "oracle_check_archive.sh"
    # 恢复
    NATIVE_RESTORE = 'oracle_native_restore.sh'
    NATIVE_LIVE_MOUNT = 'oracle_native_livemount.sh'
    NATIVE_CLIVE_MOUNT = 'oracle_native_clivemount.sh'
    NATIVE_INST_RESTORE = 'oracle_native_insrestore.sh'
    NATIVE_MOVE_DBF = 'oracle_native_move_dbfile.sh'


class OracleStartTypeEnum(int, Enum):
    # 重启oracle数据库
    START_DB = 1

    # 不重启oracle数据库
    NOT_START_DB = 0


class PluginPathConstant(str, Enum):
    INPUT_TMP_FILE_PREFIX = 'input_tmp'
    RESULT_TMP_FILE_PREFIX = 'result_tmp'
    # AGENT_ROOT_PATH作为oracle shell脚本的参数
    AGENT_ROOT_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E'
    TMP_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/tmp'
    STMP_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/stmp'
    SCRIPTS_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/Plugins/GeneralDBPlugin/bin' \
                   f'/applications/oracle/scripts'
    ORACLE_DATA_FILE_PATH = "/mnt/databackup/oracle_backup_data_path"
    ORACLE_LOG_FILE_PATH = "/mnt/databackup/oracle_log"
    NONE_ROOT_TMP_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/tmp'
    LINUX_LUN_BACKUP_TOOL = f'{get_install_head_path()}/DataBackup/ProtectClient/Plugins/GeneralDBPlugin/bin/LunOpTool'

    LINUX_HOST_SN_FILE_PATH = '/etc/HostSN/HostSN'
    WINDOWS_TMP_PATH = f'{adaptation_win_path()}/DataBackup/ProtectClient/ProtectClient-E/tmp'
    WINDOWS_STMP_PATH = f'{adaptation_win_path()}/DataBackup/ProtectClient/ProtectClient-E/stmp'
    WINDOWS_HOST_SN_FILE_PATH = f'{adaptation_win_path()}/DataBackup/ProtectClient/ProtectClient-E/conf/HostSN'
    WINDOWS_ORACLE_DATA_FILE_PATH = f"{get_install_head_path()}\\DataBackup\\ProtectClient" \
                                    f"\\ProtectClient-E\\oracle_backup_data_path"
    WINDOWS_ORACLE_LOG_FILE_PATH = f"{get_install_head_path()}\\DataBackup\\ProtectClient" \
                                   f"\\ProtectClient-E\\oracle_log"
    WINDOWS_ORACLE_RESTORE_DATA_FILE_PATH = f"{get_install_head_path()}\\DataBackup\\ProtectClient" \
                                            f"\\ProtectClient-E\\oracle_restore_data_path"
    WINDOWS_ORACLE_RESTORE_LOG_FILE_PATH = f"{get_install_head_path()}\\DataBackup\\ProtectClient" \
                                           f"\\ProtectClient-E\\oracle_restore_log"
    AIX_RESTORE_DATA = f"{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/oracle_restore_data"
    AIX_RESTORE_LOG = f"{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/oracle_restore_log"
    POWER_SHELL_PATH = 'C:/WINDOWS/system32/WindowsPowerShell/v1.0/powershell'
    LUN_TOOL = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/bin/LunOpTool'
    LUN_SUB_JOB_PROGRESS_PATH = f'{get_install_head_path()}/DataBackup/ProtectClient/ProtectClient-E/stmp/'
    LUN_TOOL_STOP_FILE = f'{LUN_SUB_JOB_PROGRESS_PATH}abort_oracle_backup_job'
    LUN_SUB_JOB_PROGRESS_FILE = LUN_SUB_JOB_PROGRESS_PATH + 'report_{}.rep'
    ORACLE_BACKUP_PFILE_SUFFIX = f".ora"
    ORACLE_BACKUP_CONTROL_FILE_NAME = f"controlfile.ctl"
    # 表级恢复-辅助实例相关文件所在路径
    ORACLE_HOME_DBS_PATH = "dbs"
    ORACLE_HOME_LOG_PATH = "rdbms/log"
    ORACLE_HOME_AUDIT_PATH = "rdbms/audit"
    ORACLE_HOME_RDBMS_PATH = "rdbms"
    ORACLE_HOME_TRACE_PATH = "trace"
    ORACLE_BASE_ADMIN_PATH = "admin"


class ListAppQueryConstant(str, Enum):
    DATABASE = 'database'
    TABLE = 'table'
    ASM = 'asm'
    RAC = 'rac'
    DISKINFO = 'diskInfo'
    PDB_INFO = 'pdbInfo'
    PDB = 'pdb'
    ORACLE_CLUSTER_ENV = 'Oracle-clusterEnv'
    ORACLE_CLUSTER = 'Oracle-cluster'


class OracleResourceKeyName:
    LIST_APPLICATION_AUTH_AUTHKEY = "applications_0_auth_authKey_"
    LIST_APPLICATION_AUTH_AUTHPWD = "applications_0_auth_authPwd_"


class TaskType:
    RESOURCE_SERVICE = "RESOURCE"
    BACKUP_SERVICE = "BACKUP"


class LunToolStatus:
    REPORT_STATUS_PREP = "PREPARE"
    REPORT_STATUS_PROG = "IN_PROG"
    REPORT_STATUS_FAIL = "FAIL"
    REPORT_STATUS_SUCC = "SUCCESS"
    REPORT_STATUS_STOP = "STOP"


class OracleProgress:
    PROGRESS_ONE_HUNDRED = 100
    PROGRESS_FIFTY = 50


class PMAuthTypeEnum:
    OS_AUTH = 1  # OS认证
    DATABASE_AUTH = 2  # 数据库认证


class ShellAuthTypeEnum:
    OS_AUTH = 1  # OS认证
    DATABASE_AUTH = 0  # 数据库认证


class InstanceOnlineStatus:
    INSTANCE_OFFLINE = 1  # 离线
    INSTANCE_ONLINE = 0  # 在线


# PM auth_type 与 脚本auth_type枚举值不一致 故需要映射PM->脚本
AuthTypeMap = {
    PMAuthTypeEnum.OS_AUTH: ShellAuthTypeEnum.OS_AUTH,
    PMAuthTypeEnum.DATABASE_AUTH: ShellAuthTypeEnum.DATABASE_AUTH
}

# 脚本auth_type枚举对应的认证方式字符串
AuthTypeMapToStr = {
    ShellAuthTypeEnum.OS_AUTH: 'OS',
    ShellAuthTypeEnum.DATABASE_AUTH: 'Database'
}


class OracleDataBaseType:
    ORACLE = 'Oracle'
    ORACLE_CLUSTER = 'Oracle-cluster'
    ORACLE_CLUSTER_INSTANCE = 'Oracle-clusterInstance'
    ORACLE_PDB = 'Oracle-pdb'


class BackupTypeStr:
    # 备份类型（传给小工具）
    FULL_BACKUP = 'full_backup'
    INCRE_BACKUP = 'incre_backup'


class BackupSubJobName:
    MOUNT_BIND = "mount_bind"
    SECRET_TASK = 'secret_task'
    BACK_TASK = "backup"
    CHECK_TASK = 'check_task'
    SNAPSHOT_TASK = "exec_snapshot"
    BACKUP_PRE_TASK = "backup_pre_task"
    BACKUP_LUN = "backup_lun"


class OracleTruncateLog:
    TRUNCATE_LOG = 0
    NO_TRUNCATE_LOG = 1


# "true" 表示删除归档日志 "false"表示不删除归档日志
class DeleteTrunCateLog:
    Delete_Truncate_Log = "true"
    Not_Delete_Truncate_Log = "false"


OracleTruncateLogMap = {
    DeleteTrunCateLog.Delete_Truncate_Log: OracleTruncateLog.TRUNCATE_LOG,
    DeleteTrunCateLog.Not_Delete_Truncate_Log: OracleTruncateLog.NO_TRUNCATE_LOG
}


class PexpectResult:
    OS_LOGIN_RESULT = [pexpect.TIMEOUT, pexpect.EOF, "SQL"]
    PASS_WORD = [pexpect.TIMEOUT, pexpect.EOF, "Password:"]
    ENTER_PASS_WORD = [pexpect.TIMEOUT, pexpect.EOF, "Enter password:"]
    CONNECT_TO = [pexpect.TIMEOUT, pexpect.EOF, "Connected", "Connected to an idle instance"]
    OPEN_STATUS = [pexpect.TIMEOUT, pexpect.EOF, r"<table.*</table>"]
    ALTER_DATABASE = [pexpect.TIMEOUT, pexpect.EOF, "Database altered"]
    ALTER_DATABASE_FILE = [pexpect.TIMEOUT, pexpect.EOF, "Database altered", "nonexistent"]
    TABLE_SPACE_ALTERED = [pexpect.TIMEOUT, pexpect.EOF, "Tablespace altered"]
    SYSTEM_ALTERED = [pexpect.TIMEOUT, pexpect.EOF, "System altered"]
    DISKGROUP_ALTERED = [pexpect.TIMEOUT, pexpect.EOF, "Diskgroup altered", "is already mounted"]
    DATABASE_OPENED = [pexpect.TIMEOUT, pexpect.EOF, "Database opened", "Database altered", "already-running"]
    DATABASE_MOUNTED = [pexpect.TIMEOUT, pexpect.EOF, "Database mounted"]
    RECOVERY_COMPLETE = [pexpect.TIMEOUT, pexpect.EOF, "Media recovery complete", "file is in use or recovery"]
    ASM_STARTED = [pexpect.TIMEOUT, pexpect.EOF, "ASM instance started", "ASM diskgroups mounted", "already-running"]
    PFILE_CREATED = [pexpect.TIMEOUT, pexpect.EOF, "File created"]
    SHUTDOWN = [pexpect.TIMEOUT, pexpect.EOF, "ORACLE instance shut down"]
    GRANT_SUCCEEDED = [pexpect.TIMEOUT, pexpect.EOF, "Grant succeeded"]
    EXPDP_IMPDP_SUCCEEDED = [pexpect.TIMEOUT, pexpect.EOF, "logon denied", "successfully completed"]
    SESSION_ALTERED = [pexpect.TIMEOUT, pexpect.EOF, "Session altered"]
    DIRECTORY_CREATED = [pexpect.TIMEOUT, pexpect.EOF, "Database altered.", "Directory created"]
    DIRECTORY_DROPPED = [pexpect.TIMEOUT, pexpect.EOF, "Directory dropped", "does not exist"]
    USER_DROPPED = [pexpect.TIMEOUT, pexpect.EOF, "User dropped"]
    TABLE_DROPPED = [pexpect.TIMEOUT, pexpect.EOF, "Table dropped"]
    PDB_TABLE_DROPPED = [pexpect.TIMEOUT, pexpect.EOF, "Session altered", "Table dropped"]
    PDB_OPENED = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database altered", "already open",
                  "procedure successfully completed"]
    CLOSE_PDB = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database altered", "already closed"]
    CLOSE_PDB_FORCE = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database altered", "already closed", "does not exist"]
    UNPLUG_PDB = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database altered"]
    DROP_PDB = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database dropped", "does not exist"]
    CREATE_PDB = [pexpect.TIMEOUT, pexpect.EOF, "Pluggable database created"]
    IS_PLUGGABLE_YES = [pexpect.TIMEOUT, pexpect.EOF, "IS_PLUGGABLE_YES"]
    NO_ROWS_SELECTED = [pexpect.TIMEOUT, pexpect.EOF, r"<table.*</table>", "no rows selected"]
    FILE_PATH = [
        pexpect.TIMEOUT,
        pexpect.EOF,
        r"<table.*</table>",
        "no rows selected",
        "none of the files are in backup",
        "is already in backup"
    ]
    LUN_BACKUP = [
        pexpect.TIMEOUT,
        pexpect.EOF,
        '[#\$>]',
        "Init LunOpTool Success!"
    ]
    CREATE_INSTANCE_RES = [pexpect.TIMEOUT, pexpect.EOF, "Instance created"]
    CREATE_TABLESPACE_RES = [pexpect.TIMEOUT, pexpect.EOF, "Tablespace created."]


class ArchiveLogMode(str, Enum):
    NOARCHIVELOG = "NOARCHIVELOG"
    ARCHIVELOG = "ARCHIVELOG"
    MANUAL = "MANUAL"


class OpenMode(str, Enum):
    READONLY = "READ ONLY"
    READWRITE = "READ WRITE"
    MOUNTED = "MOUNTED"


class InstanceStatus(str, Enum):
    STARTED = "STARTED"
    MOUNTED = "MOUNTED"
    OPEN = "OPEN"
    OPEN_MIGRATE = "OPEN MIGRATE"


class ListTableByOwnerParam(BaseModel):
    owner: str
    pdb_name: str
    page: int
    page_size: int


class PageParamConst:
    # 分页查询默认页号
    PAGE = 1
    # 分页查询默认页面大小
    PAGE_SIZE = 2000


class OracleFilePathSql(str, Enum):
    DATA = 'select name from v$datafile;'
    CONTROL = 'select name from v$controlfile;'
    LOG = 'select MEMBER from v$logfile;'
    SP_FILE = "select value from V$parameter where name = 'spfile';"
    P_FILE = "select value from V$parameter where name = 'pfile';"
    ASM_DISK_PATH = "select path from v$asm_disk_stat;"
    BACKUP_MODE = "SELECT status FROM v$backup WHERE status = 'ACTIVE';"


class DataBaseRole:
    PRIMARY = "PRIMARY"


class Platform:
    WINDOWS = "windows"
    AIX = "aix"


class QueryOracleInfoResult:
    INVALID_CONTENT_PRECISE_MATCH = ['NAME', 'MEMBER', 'VALUE', 'PATH']
    INVALID_CONTENT_FUZZY_MATCH = ['-----', 'rows selected']


class ErrorCode(Enum):
    SUCCESS = 0
    # 参数错误
    ERROR_COMMON_INVALID_PARAM = 1073948954
    # 脚本执行失败
    ERROR_COMMON_SCRIPT_EXEC_FAILED = 1073948968
    # 通用代理执行任务时，由于插件鉴权失败，操作失败
    PLUGIN_CANNOT_BACKUP_ERR = 1677929228
    # Agent增量备份无法进行，需要转成全量备份
    INC_TO_FULL_ERR = 1577209901
    # 插件日志备份无法进行，需要转成全量备份
    LOG_TO_FULL_ERR = 1577213517
    # 数据库离线
    DATABASE_OFFLINE_ERR = 1577210050
    # 数据库实例服务异常
    ERROR_INSTANCE_NOSTART = 1577209975
    # 数据库未开启归档模式
    ARCHIVE_MODE_NOT_ENABLED = 1577210051
    # 备份失败
    BACKUP_FAILED = 1577213471
    # 数据库未关闭 0x5E025007
    DB_NOT_CLOSED = 1577209863
    # 内部错误 0x5F02573B
    INTERNAL_ERROR = 1593988923
    # 恢复oracle失败 0x64025006
    ERROR_AGENT_RESTORE_DATABASE_FAILED = 1677873158
    # 执行脚本失败 未找到omrp错误码
    SCRIPT_EXEC_FAILED = 0x40032928
    # oracle未安装 未找到omrp错误码
    ORACLE_NOT_INSTALLED = 44
    # 执行SQL语句出错 0x400329A5 读取执行结果文件内容上报错误详情
    ORACLE_EXEC_SQL_FAILED = 1073949093
    # 执行RMAN失败 0x400329A6 读取执行结果文件内容上报错误详情
    ERROR_ORACLE_EXEC_RMAN_FAILED = 1073949094
    # 恢复失败 未找到
    ERROR_RESTORE_FAILED = 175
    # 执行Oracle恢复操作时，由于目标主机和原主机上的Oracle版本不匹配，操作失败 0x5E02500F
    ERROR_ORACLE_VERSION_DISMATCH = 1577209871
    # TNS适配器错误 未找到omrp错误码
    ERROR_ORACLE_TNS_PROTOCOL_ADAPTER = 0x400329A2
    # 数据库实例未启动 未找到omrp错误码
    ERROR_COMMON_RECOVER_INSTANCE_NOSTART = 0x4003291C
    # 数据库连接已超过最大连接数 未找到omrp错误码
    ERROR_ORACLE_OVER_MAX_LINK = 0x40032995
    # 数据库用户名或密码错误 未找到omrp错误码
    ERROR_COMMON_DB_USERPWD_WRONG = 1577209986
    # 数据库（{0}）不存在
    ERROR_COMMON_DB_PARAM_WRONG = 1577210047
    # 数据库用户权限不足 未找到omrp错误码
    ERROR_COMMON_DB_INSUFFICIENT_PERMISSION = 0x4003291E
    # 数据库未开启归档模式 0x40032993
    ERROR_ORACLE_NOARCHIVE_MODE = 1073949075
    # 数据库已处于热备模式 未找到omrp错误码
    ERROR_ORACLE_IN_BACKUP = 0x40032996
    # 数据库未处于热备模式 未找到omrp错误码
    ERROR_ORACLE_NOT_IN_BACKUP = 0x40032997
    # 数据库已处于运行状态 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYRUNNING = 0x5E025007
    # 数据库已处于挂载状态 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYMOUNT = 0x4003299A
    # 数据库已处于打开状态 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYOPEN = 0x4003299B
    # oracle数据库未打开 0x400329AA
    ERROR_ORACLE_DB_NOT_OPEN = 1073949098
    # ASM磁盘组已被挂载 未找到omrp错误码
    ERROR_ORACLE_ASM_DISKGROUP_ALREADYMOUNT = 0x4003299C
    # ASM磁盘组未被挂载 未找到omrp错误码
    ERROR_ORACLE_ASM_DISKGROUP_NOTMOUNT = 0x4003299D
    # 参数错误
    ERROR_PARAM_INVALID = 1577209881
    # 原因:获取数据库版本信息失败,建议：请检查数据库服务是否正常
    ERROR_ORACLE_NOT_INSTALLED = 1577209944
    # ORACLE_BASE不存在
    ERROR_SCRIPT_ORACLEBASE_LOST = 1073949100
    # ORACLE_HOME不存在
    ERROR_SCRIPT_ORACLEHOME_LOST = 1073949101
    # 挂载目录不存在或无操作权限
    ERROR_MOUNTPATH = 1577209864
    # 备份日志副本文件失败
    ERROR_ORACLE_BACKUP_FAILED = 1577213488
    # 与数据库已配置的认证方式不一致
    ERROR_AUTH_TYPE = 1677931371
    # 恢复后的首次日志备份失败
    ERROR_ORACLE_FIRST_BACKUP_FAILED = 1577213502
    # 从库备份需要数据库认证
    ERROR_STANDBY_DATABASE_NEED_DB_AUTH = 1577213504
    # ORACLE认证信息错误
    ERROR_ORACLE_AUTH_INFO_FAILED = 1577213519
    # 数据库连接已超过最大连接数
    ERROR_ORACLE_APPLICATION_OVER_MAX_LINK = 1577211394
    # 主备库sequence号不一致
    ERROR_PRIMARY_STANDBY_DIFFERENT = 1677873250
    # 备份数据不完整
    DATA_FILE_IN_COMPLETE = 1577211395
    # ORACLE认证信息错误
    ERROR_STORAGE_AUTH_INFO_FAILED = 1577213538
    # ORACLE存储型号错误
    ERROR_STORAGE_MODEL_FAILED = 1677935111
    # 执行存储快照备份前置任务时，由于创建LUN快照失败，操作失败
    ERROR_CREATE_LUN_SNAPSHOTS = 1677873191
    # 错误的低权限用户信息
    ERROR_INVALID_LOW_AUTH_INFO = 1677873239
    # 证书过期或无效
    ERROR_INVALID_CERT = 1677931024
    # 证书被吊销
    ERROR_CERT_REVOKE = 1677931037
    # 表级恢复数据库中存在同名表
    ERROR_EXIST_SAME_TABLE_NAME = 1577213570
    # 数据库未开启读写模式
    ERROR_ORACLE_NO_READWRITE_MODE = 1577213571
    # 数据库初始化参数COMPATIBLE版本小于11.1.0
    ERROR_ORACLE_COMPATIBLE_VERSION_LOWER = 1577213572
    # 当前环境同时存在Oracle单机实例和Oracle集群实例
    ERROR_CHECK_ORACLE_INSTALL_TYPE = 1677873255
    # 原因：吊销列表已过期。建议：请更换有效的吊销列表后重试。
    ERROR_CRL_SIGNATURE_FAILURE = 1677931040
    # 数据库归档日志不连续({0}~{1})。
    ERROR_ORACLE_HAS_LOG_LOST = 1577088257
    # 恢复目标路径不存在或无读写权限
    RECOVER_PATH_NOT_EXISTS = 1577213598


class OracleReportLabel:
    # 开始执行存储快照备份子任务（{0}），拷贝LUN数据（{1}）。
    STORAGE_SNAPSHOT_BACKUP_SUB_START_COPY = "plugin_start_storage_snapshot_backup_copy_subjob_label"
    # 当前是存储快照模式，通道数、传输和存储加密配置不生效。
    STORAGE_SNAPSHOT_BACKUP_TIPS = "plugin_storage_snapshot_backup_copy_subjob_tips_label"
    #  该资源存在正在执行的其他非日志备份任务，日志备份转全量备份失败。建议：请待其他非日志备份任务结束后重新下发日志备份。
    LOG_CONVERT_TO_FULL_FAILED = "plugin_log_convert_to_full_failed_label"
    # OCR或Voting Files所在磁盘和数据文件所在磁盘在同一个lun上，不支持新位置恢复
    STORAGE_SNAPSHOT_OCR_DATA_HAS_SAME_LUN_LABEL = "plugin_storage_snapshot_ocr_data_has_same_lun_label"
    # OCR或Voting Files所在磁盘和日志文件所在磁盘在同一个lun上，不支持新位置恢复
    STORAGE_SNAPSHOT_OCR_LOG_HAS_SAME_LUN_LABEL = "plugin_storage_snapshot_ocr_log_has_same_lun_label"
    # 子任务（{0}）执行成功。已将数据恢复到{1},请到{1}查看。
    ORACLE_SUB_JOB_SUCCESS_DATA_START_LABEL = "oracle_plugin_sub_job_success_data_start_label"
    # 当前备份任务中待备份的lun数量或大小与前一次备份不一致
    PLUGIN_LUN_NOT_SAME_WITH_PRE_LABEL = "plugin_lun_not_same_with_pre_label"
    # 恢复任务可能存在资源残留，请在《故障处理》中搜索“恢复任务提示存在资源残留”章节，根据处理步骤清除残留的资源（{0}）。
    ORACLE_RESTORE_ASSIST_INSTANCE_RESOURCE_RESIDUE_LABEL = \
        "plugin_restore_assist_instance_resource_residue_label"
    # 可用的存储设备和上次备份不一致，需要转全量备份，如果是双活存储，请检查双活状态是否正常。
    AVAILABLE_STORAGE_NOT_EQUAL_LAST_BACKUP_LABEL = "plugin_available_storage_not_equal_last_backup_label"
    # 挂载成功，目标数据库已开启，开始迁移数据。
    MOUNT_SUCCESS_DATABASE_START_DATA_MIGRATION_START_LABEL = "mount_success_database_start_data_migration_start_label"
    # 无法备份表级恢复所需数据，请检查PDB状态。
    ORACLE_BACKUP_PLEASE_CHECK_THE_PDB_STATUS_LABEL = "plugin_backup_please_check_the_pdb_status_label"
    # 存储池（{0}）空间使用率（{1}%）超过限制（{2}%）。The storage pool({0}) space usage({1}%) exceeds the upper limit({2}%).
    ORACLE_STORAGE_USAGE_LIMIT_LABEL = "oracle_plugin_storage_snapshot_capacity_usage_limit_label"
    # 当前备份任务中待备份的lun数量或大小与前一次备份不一致，请先执行全量备份后重试。
    plugin_log_backup_lun_not_same_with_pre_label = "plugin_log_backup_lun_not_same_with_pre_label"
    # 表级恢复任务失败。原因：未配置PDB（{0}）的 tnsnames.ora 配置文件，请参考产品文档中“恢复Oracle数据库中的单个表或多个表”章节，修改目标主机中Oracle软件的 tnsnames.ora 配置文件。
    PLUGIN_TNS_NOT_CONFIGURED_LABEL = "plugin_tns_not_configured_label"
    # 副本数据不完整无法恢复
    PLUGIN_CHECK_BACKUP_ARCHIVELOG_LOST_LABEL = "plugin_check_backup_archivelog_lost_label"
    # 连接存储异常。建议：请确保存储认证信息正确，用户状态正常，存储状态正常，网络状态正常。
    PLUGIN_STORAGE_AUTH_INFO_FAILED_LABEL = "plugin_storage_auth_info_failed_label"
    # 数据副本可以恢复至生产端时间：{0}。
    PLUGIN_FULL_BACKUP_RESTORE_TIMESTAMP_LABEL = "plugin_full_backup_restore_timestamp_label"


class ScriptExitCode:
    SUCCESS = 0
    # 脚本执行失败
    ERROR_SCRIPT_EXEC_FAILED = 5
    # 未找到omrp错误码
    ERROR_ORACLE_NOT_INSTALLED = 44
    # 执行oracle sql失败
    ERROR_ORACLE_EXESQL_FAILED = 61
    # 执行oracle rman失败
    ERROR_ORACLE_EXERMAN_FAILED = 62
    # 恢复失败
    ERROR_RESTORE_FAILED = 175
    # oracle版本不匹配
    ERROR_ORACLE_VERSION_DISMATCH = 186
    # TNS适配器错误 0x400329A2 未找到omrp错误码
    ERROR_ORACLE_TNS_PROTOCOL_ADAPTER = 43
    #  数据库实例未启动 0x4003291C 未找到omrp错误码
    ERROR_INSTANCE_NOSTART = 11
    # 数据库连接已超过最大连接数 0x40032995 未找到omrp错误码
    ERROR_ORACLE_APPLICATION_OVER_MAX_LINK = 28
    # 数据库用户名或密码错误 0x4003291D 未找到omrp错误码
    ERROR_DB_USERPWD_WRONG = 10
    # 数据库用户权限不足 0x4003291E 未找到omrp错误码
    ERROR_INSUFFICIENT_WRONG = 15
    # 数据库未开启归档模式 0x40032993
    ERROR_ORACLE_NOARCHIVE_MODE = 24
    # 超出日志文档阈值
    ERROR_ORACLE_OVER_ARCHIVE_USING = 25
    # 数据库已处于热备模式 0x40032996 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADY_INBACKUP = 29
    # 数据库未处于热备模式 0x40032997 未找到omrp错误码
    ERROR_ORACLE_DB_INHOT_BACKUP = 30
    # 数据库已处于运行状态 0x40032999 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYRUNNING = 31
    # 数据库已处于挂载状态 0x4003299A 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYMOUNT = 32
    # 数据库已处于打开状态 0x4003299B 未找到omrp错误码
    ERROR_ORACLE_DB_ALREADYOPEN = 33
    # oracle数据库未打开 0x400329AA
    ERROR_ORACLE_NOT_MOUNTED = 40
    # oracle数据库未打开 0x400329AA
    ERROR_ORACLE_NOT_OPEN = 41
    # 未找到
    ERROR_ORACLE_ANOTHER_STARTING = 45
    # 未找到
    ERROR_ORACLE_DB_BUSY = 46
    # 未找到
    ERROR_ORACLE_DB_NOT_COMPLETE_SHUTDOWN = 51
    # ASM磁盘组已被挂载 0x4003299C 未找到omrp错误码
    ERROR_ORACLE_ASM_DISKGROUP_ALREADYMOUNT = 26
    # ASM磁盘组未被挂载 0x4003299D 未找到omrp错误码
    ERROR_ORACLE_ASM_DISKGROUP_NOTMOUNT = 27
    # 脚本参数错误
    ERROR_PARAM_INVALID = 12
    # 恢复路径不存在
    ERROR_ORACLE_RECOVERPATH_NOT_EXIT = 64
    # 数据库文件恢复拷贝失败
    ERROR_ORACLE_FILE_RESTORE_COPY_FAILED = 66
    # ORACLE_BASE不存在
    ERROR_SCRIPT_ORACLEBASE_LOST = 69
    # ORACLE_HOME不存在
    ERROR_SCRIPT_ORACLEHOME_LOST = 68
    # 挂载目录不存在或无操作权限
    ERROR_MOUNTPATH = 185
    # 备份日志副本文件失败
    ERROR_ORACLE_BACKUP_FAILED = 56
    # 未找到omrp错误码
    ERROR_ORACLE_TRUNCATE_ARCHIVELOG_FAILED = 42
    # 恢复后的首次日志备份失败
    ERROR_ORACLE_FIRST_BACKUP_FAILED = 91
    # 日志备份检查存在日志丢失
    ERROR_ORACLE_HAS_LOG_LOST = 92
    # 数据库认证信息失败
    ERROR_ORACLE_AUTH_INFO_FAILED = 19
    # 主备库sequence号不一致
    ERROR_PRIMARY_STANDBY_DIFFERENT = 147
    # 存储认证信息失败
    ERROR_STORAGE_AUTH_INFO_FAILED = 77
    # 存储设备型号不行
    ERROR_STORAGE_MODEL_FAILED = 78
    # 错误的低权限用户信息
    ERROR_INVALID_LOW_AUTH_INFO = 1677873239
    # 证书过期或无效
    ERROR_INVALID_CERT = 79
    # 证书被吊销
    ERROR_CERT_REVOKE = 80
    # 原因：当前环境同时存在Oracle单机实例和Oracle集群实例。
    # 建议：请使用只存在一种数据库实例类型的环境注册。
    ERROR_CHECK_ORACLE_INSTALL_TYPE = 81
    # 原因：吊销列表已过期。建议：请更换有效的吊销列表后重试。
    ERROR_CRL_SIGNATURE_FAILURE = 82


exit_code_error_code_map = {
    ScriptExitCode.ERROR_ORACLE_EXESQL_FAILED: ErrorCode.ORACLE_EXEC_SQL_FAILED,
    ScriptExitCode.ERROR_ORACLE_DB_ALREADYRUNNING: ErrorCode.ERROR_ORACLE_DB_ALREADYRUNNING,
    ScriptExitCode.ERROR_ORACLE_EXERMAN_FAILED: ErrorCode.ERROR_ORACLE_EXEC_RMAN_FAILED,
    ScriptExitCode.ERROR_ORACLE_VERSION_DISMATCH: ErrorCode.ERROR_ORACLE_VERSION_DISMATCH,
    ScriptExitCode.ERROR_ORACLE_NOARCHIVE_MODE: ErrorCode.ERROR_ORACLE_NOARCHIVE_MODE,
    ScriptExitCode.ERROR_ORACLE_NOT_MOUNTED: ErrorCode.ERROR_ORACLE_DB_NOT_OPEN,
    ScriptExitCode.ERROR_ORACLE_NOT_OPEN: ErrorCode.ERROR_ORACLE_DB_NOT_OPEN,
    ScriptExitCode.ERROR_DB_USERPWD_WRONG: ErrorCode.ERROR_COMMON_DB_USERPWD_WRONG,
    ScriptExitCode.ERROR_PARAM_INVALID: ErrorCode.ERROR_PARAM_INVALID,
    ScriptExitCode.ERROR_SCRIPT_ORACLEBASE_LOST: ErrorCode.ERROR_SCRIPT_ORACLEBASE_LOST,
    ScriptExitCode.ERROR_SCRIPT_ORACLEHOME_LOST: ErrorCode.ERROR_SCRIPT_ORACLEHOME_LOST,
    ScriptExitCode.ERROR_MOUNTPATH: ErrorCode.ERROR_MOUNTPATH,
    ScriptExitCode.ERROR_ORACLE_BACKUP_FAILED: ErrorCode.ERROR_ORACLE_BACKUP_FAILED,
    ScriptExitCode.ERROR_INSTANCE_NOSTART: ErrorCode.ERROR_INSTANCE_NOSTART,
    ScriptExitCode.ERROR_ORACLE_FIRST_BACKUP_FAILED: ErrorCode.ERROR_ORACLE_FIRST_BACKUP_FAILED,
    ScriptExitCode.ERROR_ORACLE_NOT_INSTALLED: ErrorCode.ERROR_ORACLE_NOT_INSTALLED,
    ScriptExitCode.ERROR_ORACLE_APPLICATION_OVER_MAX_LINK: ErrorCode.ERROR_ORACLE_APPLICATION_OVER_MAX_LINK,
    ScriptExitCode.ERROR_PRIMARY_STANDBY_DIFFERENT: ErrorCode.ERROR_PRIMARY_STANDBY_DIFFERENT,
    ScriptExitCode.ERROR_ORACLE_AUTH_INFO_FAILED: ErrorCode.ERROR_ORACLE_AUTH_INFO_FAILED,
    ScriptExitCode.ERROR_STORAGE_AUTH_INFO_FAILED: ErrorCode.ERROR_STORAGE_AUTH_INFO_FAILED,
    ScriptExitCode.ERROR_STORAGE_MODEL_FAILED: ErrorCode.ERROR_STORAGE_MODEL_FAILED,
    ScriptExitCode.ERROR_INVALID_LOW_AUTH_INFO: ErrorCode.ERROR_INVALID_LOW_AUTH_INFO,
    ScriptExitCode.ERROR_INVALID_CERT: ErrorCode.ERROR_INVALID_CERT,
    ScriptExitCode.ERROR_CERT_REVOKE: ErrorCode.ERROR_CERT_REVOKE,
    ScriptExitCode.ERROR_CHECK_ORACLE_INSTALL_TYPE: ErrorCode.ERROR_CHECK_ORACLE_INSTALL_TYPE,
    ScriptExitCode.ERROR_CRL_SIGNATURE_FAILURE: ErrorCode.ERROR_CRL_SIGNATURE_FAILURE,
    ScriptExitCode.ERROR_ORACLE_HAS_LOG_LOST: ErrorCode.ERROR_ORACLE_HAS_LOG_LOST
}


class ORACLEExecPower:
    ORACLE_USER = "oracle"
    ORACLE_GROUP = "oinstall"
    ORACLE_FILE_MODE = "0700"
    ORACLE_LIVE_MOUNT_PATH = "/mnt"


class ORACLEJsonConstant:
    PATH = "path"
    REMOTE_PATH = 'remotePath'
    REMOTE_HOST = "remoteHost"
    JOB = "job"
    TARGET_OBJECT = "targetObject"
    EXTEND_INFO = "extendInfo"
    MOUNT_JOB_ID = "mountJobId"
    COPY = "copy"
    COPIES = "copies"
    REPOSITORIES = "repositories"
    REPOSITORY_TYPE = "repositoryType"
    PROTECT_OBJECT = "protectObject"
    NAME = "name"
    INST_NAME = "inst_name"
    P_FILE_PARAMS = "pfileParams"
    CHANNELS = "channels"
    CHANNELS_UPPERCASE = "CHANNELS"
    META_REPOSITORY = "meta_repository"
    RECOVER_TARGET = "recoverTarget"
    RECOVER_PATH = "recoverPath"
    RESTORE_PATH = "RESTORE_PATH"
    TARGET_ENV = "targetEnv"
    TARGET_LOCATION = "targetLocation"
    TIME_STAMP = "TIME_STAMP"
    RESTORE_TIME_STAMP = "restoreTimestamp"
    SCN = "SCN"
    RESTORE_SCN = "restoreScn"
    ASM_INFO = "asm_info"
    BACKUP_ALGO = "backup_algo"
    BACKUP_ALGO_VALUE = "backup_algo_value"
    RESTORE_TARGET_HOST = "RESTORE_TARGET_HOST"
    NEW = "new"
    NODES = "nodes"
    INST_NAME_ = "instName"
    SUB_TYPE = "subType"
    INSTALL_USER_NAME = "installUsername"
    TYPE = "type"
    AUTH = "auth"
    ASM_INFO_ = "asmInfo"
    STORAGE_SNAPSHOT_FLAG = 'storage_snapshot_flag'
    COPY_TRANSPORT_MODE = 'transportMode'
    COPY_LUN_SNAPSHOTS = 'lun_snapshots'
    COPY_DISK_INFOS = 'disk_infos'
    COPY_SPFILE_PATH = 'spfile_path'
    ASM_SPFILE_PATH = 'asm_spfile_path'
    COPY_AGENT_UUID = 'agent_uuid'
    NEW_LOC_RESTORE = 'new_loc_restore'
    EXEC_STORAGE = 'exec_storage'


class BackupTransportMode(str, Enum):
    STORAGE_LAYER = 'storageLayer'


class StartDataBase(int, Enum):
    """
    是否启动数据库
    """
    # 不启动数据库
    NO = 0
    # 启动数据库
    YES = 1


DELETING_PATH_WHITE_LIST = [
    "/mnt/databackup/",
    f"{get_install_head_path()}/DataBackup/",
    "/mnt/"
]


class OracleParentPath:
    TMP = "/mnt/"
    TMPOCEANPROTECT = "/mnt/databackup/"


class RecoverTargetType(str, Enum):
    """
    oraclenativerestore.sh脚本中定义的RECOVERTARGET变量枚举值
    """
    # 恢复至原机原实例
    SAME = "0"
    # 恢复至新机
    OTHER = "2"


class CheckDBTypeEnum(str, Enum):
    """
    oraclecheckdbstatus.sh脚本提供的检查类型
    """
    CheckDBClose = "0"
    CheckDBOpen = "1"
    CheckDBExists = "2"
    # 如果数据库没有关闭，将其关闭
    ShutDownDBIfNotClose = "3"


class RestoreTarget:
    """
    PM 下发的恢复位置类型
    """
    # 新位置恢复
    NEW = 'new'
    # 原位置恢复
    ORIGINAL = 'original'


class RestoreByType:
    """
    恢复的数据类型
    """
    # 使用副本恢复
    COPY = 1
    # 任意时间点恢复
    TIME = 2
    # 使用SCN恢复
    SCN = 3


class CacheRepoFilename:
    """
    cache仓临时文件
    """
    RESTORE_PREREQUISITE_PROGRESS = 'restore_prerequisite_progress'
    RESTORE_PROGRESS = 'restore_progress'
    RESTORE_POST_PROGRESS = 'restore_post_progress'
    LIVE_MOUNT_PROGRESS = 'live_mount_progress'
    CANCEL_LIVE_MOUNT_PROGRESS = 'clive_mount_progress'
    INSTANT_PROGRESS = 'instant_progress'


class LogMetaFileName:
    """
    log仓中meta目录下的文件名称
    """
    # 存放resetlogs_id与日志备份目录的关系，用于日志恢复
    RESETLOGS_ID_MAP = 'resetlogs_id_map.json'
    LOG_LOST_FROM_SCN = 'log_lost_from_scn.json'


class RestoreJobName:
    FIRST_JOB = 'first_job'
    SECOND_JOB = 'second_job'
    STARTUP_DATABASE = 'startup_database'
    LOG_RESTORE_STARTUP_DATABASE = 'log_restore_startup_database'
    RECOVERY_LOG = "recovery_log"
    GET_LUN_INFO = "get_lun_info"
    LUN_RESTORE = "lun_restore"
    PDB_PRE_JOB = "pre_job"
    PDB_POST_JOB = "post_job"


class RestoreResultKey:
    """
    恢复子任务结果文件中的key取值
    """
    TASK_STATUS = 'task_status'
    ERROR_CODE = 'error_code'
    ERROR_PARAM = 'error_param'


class HostInfoConstants:
    IP_PREFIX = 'HOST='
    PORT_PREFIX = 'PORT='


class OracleInstallType:
    DEFAULT = 0
    RAC = 1
    RESTART_SINGLE_PLUS_ASM = 2


class OracleRecoverOrder:
    # Oracle restore_gen_sub_job非快照第一个子任务优先级设置为1
    FIRST = 1

    # Oracle restore_gen_sub_job非快照第二个子任务优先级设置为2
    SECOND = 2


class OracleCompareBackUpVersionResult:
    # ora_version > backup_all_version
    GT = 1

    # ora_version < backup_all_version
    LT = 2


class OracleIsASM:
    ASM_INSTANCE = 1
    NON_ASM_INSTANCE = 0


class WindowsRegistryParentDirectory:
    HKEY_CLASSES_ROOT = "HKEY_CLASSES_ROOT"
    HKEY_CURRENT_USER = "HKEY_CURRENT_USER"
    HKEY_LOCAL_MACHINE = "HKEY_LOCAL_MACHINE"
    HKEY_USERS = "HKEY_USERS"
    HKEY_CURRENT_CONFIG = "HKEY_CURRENT_CONFIG"


class WindowsRegistryConstantString:
    ORACLE_BASE = "ORACLE_BASE"
    ORACLE_SID = "ORACLE_SID"


class MetaDataConstant:
    TYPE_FOLDER = "d"
    TYPE_FILE = "f"


FileTypeMap = {
    'data_file': 'datafile',
    'log_file': 'logfile',
    'control_file': 'controlfile',
    'parameter_file': 'parameterfile'
}


class SliceConstant:
    HEAD_OF_STRING_OR_LIST = 0
    TAIL_OF_STRING_OR_LIST = -1
    INDEX_DIFFERENCE_BETWEEN_KEY_AND_VALUE = 2
    LENGTH_OF_BASIC_INFO = 4


class RestoreType:
    ARCHICE_RESTORE = 0
    FULL_RESTORE = 1


class OracleCmdKeyWord:
    ORACLE_DISK_TYPE = 'oracleasm'


ORACLE_SQLPLUS_ERROR_MAP = {
    'ORA-12560': {
        'detail': 'TNS protocol adapter error.',
        'code': ScriptExitCode.ERROR_ORACLE_TNS_PROTOCOL_ADAPTER
    },
    'ORA-01034': {
        'detail': 'database is not completely shut down.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_NOT_COMPLETE_SHUTDOWN
    },
    'ORA-00020': {
        'detail': 'can not connect, maximum number of processes exceeded.',
        'code': ScriptExitCode.ERROR_ORACLE_APPLICATION_OVER_MAX_LINK
    },
    'ORA-01017': {
        'detail': 'invalid username/password; logon denied.',
        'code': ScriptExitCode.ERROR_DB_USERPWD_WRONG
    },
    'ORA-01031': {
        'detail': 'insufficient privileges.',
        'code': ScriptExitCode.ERROR_INSUFFICIENT_WRONG
    },
    'ORA-01123': {
        'detail': 'cannot start online backup; media recovery not enabled.',
        'code': ScriptExitCode.ERROR_ORACLE_NOARCHIVE_MODE
    },
    'ORA-01146': {
        'detail': 'cannot start online backup - file 1 is already in backup.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_ALREADY_INBACKUP
    },
    'ORA-01142': {
        'detail': 'cannot end online backup - none of the files are in backup.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_INHOT_BACKUP
    },
    'ORA-01081': {
        'detail': 'cannot start already-running.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_ALREADYRUNNING
    },
    'ORA-01100': {
        'detail': 'database already mounted.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_ALREADYMOUNT
    },
    'ORA-01531': {
        'detail': 'a database already open by the instance.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_ALREADYOPEN
    },
    'ORA-01507': {
        'detail': 'database not mounted.',
        'code': ScriptExitCode.ERROR_ORACLE_NOT_MOUNTED
    },
    'ORA-01109': {
        'detail': 'database not open.',
        'code': ScriptExitCode.ERROR_ORACLE_NOT_OPEN
    },
    'ORA-10997': {
        'detail': 'another startup/shutdown operation of this instance inprogress.',
        'code': ScriptExitCode.ERROR_ORACLE_ANOTHER_STARTING
    },
    'ORA-01154': {
        'detail': 'database busy. Open, close, mount, and dismount not allowed now.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_BUSY
    },
    'ORA-01012': {
        'detail': 'database is not completely shut down.',
        'code': ScriptExitCode.ERROR_ORACLE_DB_NOT_COMPLETE_SHUTDOWN
    },
    'ORA-15001': {
        'detail': 'diskgroup not mount or not exist.',
        'code': ScriptExitCode.ERROR_ORACLE_ASM_DISKGROUP_NOTMOUNT
    }
}

TIME_FORMAT = "'YYYY-MM-DD_HH24:MI:SS'"
RETURN_INVALID = 1
ERROR_SCRIPT_EXEC_FAILED = 5
LOG_IS_VALID = f"(RESETLOGS_ID=(select RESETLOGS_ID from v$database_incarnation where STATUS='CURRENT')) " \
               f"and (deleted = 'NO') and (ARCHIVED='YES') and (STATUS != 'U')"
ORACLE_RESERVED_WORD = [
    'ACCESS', 'ADD', 'ALL', 'ALTER', 'AND', 'ANY', 'AS', 'ASC', 'AUDIT', 'BETWEEN', 'BY', 'CHAR',
    'CHECK', 'CLUSTER', 'COLUMN', 'COMMENT', 'COMPRESS', 'CONNECT', 'CREATE', 'CURRENT', 'DATE',
    'DECIMAL', 'DEFAULT', 'DELETE', 'DESC', 'DISTINCT', 'DROP', 'ELSE', 'EXCLUSIVE', 'EXISTS',
    'FILE', 'FLOAT', 'FOR', 'FROM', 'GRANT', 'GROUP', 'HAVING', 'IDENTIFIED', 'IMMEDIATE', 'IN',
    'INCREMENT', 'INDEX', 'INITIAL', 'INSERT', 'INTEGER', 'INTERSECT', 'INTO', 'IS', 'LEVEL',
    'LIKE', 'LOCK', 'LONG', 'MAXEXTENTS', 'MINUS', 'MLSLABEL', 'MODE', 'MODIFY', 'NOAUDIT',
    'NOCOMPRESS', 'NOT', 'NOWAIT', 'NULL', 'NUMBER', 'OF', 'OFFLINE', 'ON', 'ONLINE', 'OPTION',
    'OR', 'ORDER', 'PCTFREE', 'PRIOR', 'PRIVILEGES', 'PUBLIC', 'RAW', 'RENAME', 'RESOURCE',
    'REVOKE', 'ROW', 'ROWID', 'ROWNUM', 'ROWS', 'SELECT', 'SESSION', 'SET', 'SHARE', 'SIZE',
    'SMALLINT', 'START', 'SUCCESSFUL', 'SYNONYM', 'SYSDATE', 'TABLE', 'THEN', 'TO', 'TRIGGER',
    'UID', 'UNION', 'UNIQUE', 'UPDATE', 'USER', 'VALIDATE', 'VALUES', 'VARCHAR', 'VARCHAR2', 'VIEW',
    'WHENEVER', 'WHERE', 'WITH'
]


class EnvVariableKeys:
    run_user_pwd = "runUserPwd"
    application_auth_extendInfo_runUserPwd = "application_auth_extendInfo_runUserPwd_"
    job_targetObject_auth_extendInfo_runUserPwd = "job_targetObject_auth_extendInfo_runUserPwd_"
    job_protectObject_auth_extendInfo_runUserPwd = "job_protectObject_auth_extendInfo_runUserPwd_"


class TimeUnit:
    TIME_UNIT_DICT = {
        'h': 1,
        'd': 24,
        'w': 24 * 7,
        'M': 24 * 30,
        'Y': 24 * 365
    }

SHELL_PROFILE = {
    "ksh": [".kshrc", ".profile"],
    "csh": [".cshrc", ".login", ".tcshrc"],
    "zsh": [".zshenv", ".zprofile", ".zshrc", ".zlogin"],
    "bash": [".profile", ".bashrc", ".bash_login", ".bash_profile"]
}


class InstanceInfo:
    def __init__(
            self,
            is_asm: bool = False,
            inst_name: str = '',
            install_user_name: str = '',
            asm_inst_name: str = '',
            asm_install_user_name: str = ''):
        self.is_asm = is_asm
        self.inst_name = inst_name
        self.install_user_name = install_user_name
        self.asm_inst_name = asm_inst_name
        self.asm_install_user_name = asm_install_user_name


class ChannelsNum:
    ZERO_CHANNELS_NUM = 0
    DEFAULT_CHANNELS_NUM = 4
    MAX_CHANNELS_NUM = 254
